<?php
ob_start();
session_start();
include "checksession.php";
?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       <title>Adinop Co., Ltd. was founded as an ingredients importer and local manufacturers’ distributor in 1986. We also function as an exporter of finished products</title>
		<link href="../images/it_service_logo.png" rel="shortcut icon" type="image/x-icon" />
        <link rel="stylesheet" href="../css/style.css"/>
        <script type="text/javascript" src="../js/jquery/jquery.js"></script>
		<script type="text/javascript" src="../js/jquery/jquery.validationEngine.js"></script>
		<link rel="stylesheet" href="../css/validationEngine.jquery.css" type="text/css" />
		<script type="text/javascript" src="../fancybox/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
	  <script type="text/javascript" src="../fancybox/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
	  <link rel="stylesheet" type="text/css" href="../fancybox/fancybox/jquery.fancybox-1.3.4.css" media="screen" />
 	  <link rel="stylesheet" href="../fancybox/style.css" />
           <script type="text/javascript"> 
		$(function(){
			var objSet="#txtKeyword";
			var objSetText="ค้นหาด้วย รหัส,ชื่อ,แผนก,หมายเลขเครื่อง";
			if($(objSet).val()==""){
					$(objSet).val(objSetText);
			}	
			$(objSet).focus(function(){
				if($(objSet).val()==objSetText){
						$(objSet).val("");
				}	
			}).blur(function(){
				if($(objSet).val()==""){
						$(objSet).val(objSetText);
				}	
			});
		});
	   </script>
          
           <script type="text/javascript">
               $(document).ready(function() {
		
			$("#addCom").fancybox({
				'width'				: '100%',
				'height'			: '100%',
				'autoScale'			: true,
				'scrolling'		    : 'auto',
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'none',
				'type'				: 'iframe',
				'overlayColor'		: '#000',
				'hideOnOverlayClick': false,
				onCleanup   : function() {
                return window.location.reload();
					 }
			});

			$('a[id^="edit"]').fancybox({
				'width'				: '100%',
				'height'			: '100%',
				'autoScale'     	: true,
				'scrolling'		    : 'auto',
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'none',
				'type'				: 'iframe',
				'overlayColor'		: '#000',
				'hideOnOverlayClick': false,
				onClosed	:	function() {
					parent.location.reload(true); 
					  }
			});

			$('a[id^="delete"]').fancybox({
				'width'				: '20%',
				'height'			: '20%',
				onStart		:	function() {
					return window.confirm('คุณต้องการลบรายการนี้ไหม?');
				},
				onClosed	:	function() {
					parent.location.reload(true); 
					  }
			});

				
		
		});
	</script>
    </head>
<body> 
<body class="body">
    <table align="center" width="90%">
        <tr>
            <td colspan="2" class="header" >
                <img src="../images/logo.png"> <img src="../images/it_service_text.png" width ="150">
                <hr/>
            </td>
        </tr >

        <tr  valign="top">
            <td class="left">
                <?php include_once "left.php"; ?>
            </td>
            <td>
                <div align="right">
                    <form name="frmSearch" method="get" action="<?= $_SERVER['SCRIPT_NAME']; ?>">
                        <input name="txtKeyword" size="30" type="text" id="txtKeyword" value="<?= $_GET["txtKeyword"]; ?>" class="validate[required]">
<!--                                    <input type="submit" value="Search"></th>-->
                        <input type="image" name="search" id="search" value="submit" src="../images/search.png" OnClick="document.all.hidOK.value = 'submit';" alt="เข้าสู่ระบบ">
                    </form>

                </div>
                <?
                if ($_GET["txtKeyword"] != "") {
                    include_once '../connect.php';
                    // Search By Name or Email
//                    $strSQL = "SELECT a.*, b.* 
//                        FROM comname a 
//                        INNER JOIN computer b 
//                        ON a.cn_number = b.cn_number
//                        WHERE a.cn_number LIKE '%" . $_GET["txtKeyword"] . "%' or b.emp_id LIKE '%" .$_GET["txtKeyword"]."%'";
                           
                     $strSQL = "SELECT  *  FROM comname LEFT  JOIN depart ON comname.de_id = depart.id
                                                         LEFT  JOIN computer ON comname.cn_id = computer.cn_id                                                      
                                                         LEFT  JOIN employee ON comname.emp_id = employee.emp_id
                                                         LEFT  JOIN userlog  ON comname.id_member = userlog.id_member
                                                         LEFT  JOIN product_detail ON comname.cn_number =  product_detail.pd_id
   WHERE product_detail.pd_name LIKE '%". $_GET["txtKeyword"] . "%' or comname.emp_id LIKE '%" .$_GET["txtKeyword"]."%' or employee.emp_nameTh LIKE '%" .$_GET["txtKeyword"]."%' or employee.emp_nameEng LIKE '%" .$_GET["txtKeyword"]."%' or depart.departname LIKE '%" .$_GET["txtKeyword"]."%' or comname.cn_comeName LIKE '%" .$_GET["txtKeyword"]."%'"  ;     
 
  
                                           
                   
//                    $strSQL = "SELECT * FROM  comname WHERE (cn_number LIKE '%" . $_GET["txtKeyword"] . "%' or cn_comeName LIKE '%" . $_GET["txtKeyword"] . "%')";
                    $objQuery = mysql_query($strSQL) or die("Error Query [" . $strSQL . "]");
                  
                    
                    $Num_Rows = mysql_num_rows($objQuery);


                    $n = 1;
                    $Per_Page = 7;   // Per Page

                    $Page = $_GET["Page"];
                    if (!$_GET["Page"]) {
                        $Page = 1;
                    }

                    $Prev_Page = $Page - 1;
                    $Next_Page = $Page + 1;

                    $Page_Start = (($Per_Page * $Page) - $Per_Page);
                    if ($Num_Rows <= $Per_Page) {
                        $Num_Pages = 1;
                    } else if (($Num_Rows % $Per_Page) == 0) {
                        $Num_Pages = ($Num_Rows / $Per_Page);
                    } else {
                        $Num_Pages = ($Num_Rows / $Per_Page) + 1;
                        $Num_Pages = (int) $Num_Pages;
                    }


                    $strSQL .=" order  by cn_createdate DESC LIMIT $Page_Start , $Per_Page";
                    $objQuery = mysql_query($strSQL);
                    ?>
                   <div align="right">
                                <a id="addCom" href="addListCom.php">
                                <img src="../images/computer_add.png" width="40px" >
                            </a>
                               <a id="addnotebook" href="addNotebookListCom.php">
                                <img src="../images/addnotebook.png" width="40px" >
                            </a>
                        
                            <a href="report_computername.php" target="bank">
                                <img src="../images/print_empty.png" width="45px">
                            </a>
							<a href="report_recordmaintenance.php" target="bank">
                                <img src="../images/reportmaintenance.png" width="45px">
                            </a>
                        </div>
                    <div class="nameTitle">รายชื่อเครื่องคอมพิวเตอร์</div>
                    <table width="100%"  border="0" align="center" cellpadding="1" cellspacing="0" class="simply">
                        <thead>
                            <tr>
                                                    <th width="5%">ลำดับ</th>
                                                    <th width="10%">รหัสเครื่อง</th>
                                                    <th width="10%">ชื่อเครื่อง</th>
                                                     <th width="10%">รหัสพนักงาน</th>
                                                      <th width="10%">ชื่อผู้ใช้</th>
                                                    <th width="10%">แผนกฝ่าย</th>
                                                    <th width="10%">IP Address</th>
                                                    <th width="10%">ผู้จัดทำ</th>
                                                    <th width="5%">แก้ไข</th>
                                                    <th width="5%">ลบ</th>
                                                    <th width="5%">Report</th>
                                                </tr>
                        </thead>
                        <?
                        while ($objResult = mysql_fetch_array($objQuery)) {
                            ?>
                           <tr>
                                                        <td>  <?php echo $n++; ?></td>
                                                        <td><?= $objResult["pd_name"]; ?></td>
                                                        <td><?= $objResult["cn_comeName"]; ?></td>
                                                         <td><?= $objResult["6"]; ?></td>
                                                          <td><?= $objResult["emp_nameEng"]; ?></td>
                                                        <td><?= $objResult["departname"]; ?></td>
                                                        <td><?= $objResult["cn_ip"]; ?></td>
                                                        <td><?= $objResult["f_name"]; ?></td>
                                                        <td> <a id="edit<?= $n; ?>" href="updateListCom.php?cn_id=<?= $objResult["0"]; ?>">
                                                <img src="../images/write.png" width="35px" > </td>
                                                    <td align="center">
                                                        <a href="home.php?url=listCom_delete&cn_id=<?= $objResult["0"]; ?>&c_id=<?= $objResult["c_id"]; ?>&emp_id=<?= $objResult["emp_id"]; ?>&cn_number=<?= $objResult["cn_number"]; ?>&c_keyboard=<?= $objResult["c_keyboard"]; ?>&c_mouse=<?= $objResult["c_mouse"]; ?>&c_monitor=<?= $objResult["c_monitor"]; ?> "onclick="return confirm('what do you want Delete')">
                                                            <img src="../images/deletered.png" width="35px" >
                                                        </a>
                                                    </td>
                                                    <td> <a href="report_recordcomputer.php?cn_id=<?= $objResult["0"]; ?>&c_refNumber=<?= $objResult["c_refNumber"]; ?>"target="bank">
                                                            <img src="../images/pdf.png" width="35px" >
                                                        </a>
                                        
                                                        </tr>
                            <?
                        }
                        ?>
                        </tbody>
                    </table>
                    <table width="100%"  border="0" align="center" cellpadding="1" cellspacing="0" class="simply">
                        <tr>
                            <td>
                                <br>
                                Total <?= $Num_Rows; ?> Record : <?= $Num_Pages; ?> Page :
                                <?
                                if ($Prev_Page) {
                                    echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtKeyword=$_GET[txtKeyword]'><< Back</a> ";
                                }

                                for ($i = 1; $i <= $Num_Pages; $i++) {
                                    if ($i != $Page) {
                                        echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtKeyword=$_GET[txtKeyword]'>$i</a> ]";
                                    } else {
                                        echo "<b> $i </b>";
                                    }
                                }
                                if ($Page != $Num_Pages) {
                                    echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtKeyword=$_GET[txtKeyword]'>Next>></a> ";
                                }
                            }
                            ?>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>  
        <tr>
            <td colspan="2">
                <div><a href="checklogout.php" onclick="return confirm('what do you want Exit')"> <img src="../images/logout.png" width="150px"></img></a></div>
            </td>
        </tr>
        <tr>
            <td class="footer" colspan="2">
                Powered by Department Technology information Adinop
            </td>
        </tr>
    </table>
</body>
</html>